<template>
  <div>
    <page-dialog
      :title="title"
      v-model:visible="shows"
      :width="dialogInfo.width"
      :bt-list="dialogInfo.btList"
    >
      <page-form
        class="paddingBox order-model-formBox flex_wrap_start_start"
        v-model:ref-obj="formInfo.ref"
        :data="formInfo.data"
        :field-list="formInfo.fieldList"
        :rules="formInfo.rules"
        :label-width="formInfo.labelWidth"
      >
      </page-form>
    </page-dialog>
  </div>
</template>
<script setup name="selectAsset">
const { proxy } = getCurrentInstance()
const emits = defineEmits()
const props = defineProps({
  showDialog: {
    type: Boolean,
    default: false,
  },
  tableRow: {
    type: Object,
    default: function () {
      return {}
    },
  },
  title: {
    type: String,
    default: '盘亏说明',
  },
})
const formInfo = ref({
  ref: null,
  data: props.tableRow,
  fieldList: [
    {
      label: '盘亏说明',
      value: 'lossDescription',
      type: 'textarea',
    },
  ],
  labelWidth: '100px',
})
// 弹窗相关
const dialogInfo = ref({
  width: '660px',
  btLoading: false,
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '保存',
      type: 'primary',
      event: save,
      show: true,
    },
  ],
})
const shows = computed({
  get() {
    return props.showDialog
  },
  set(newValue) {
    emits('update:showDialog', newValue) // 更新父组件visible
  },
})
function save() {
  if (!formInfo.value.data.lossDescription) {
    proxy.$message({
      message: '请输入盘亏说明',
      type: 'warning',
      duration: 3500,
      showClose: true,
    })
    return
  }
  handleClose()
  emits('callback', formInfo.value.data)
}

// 关闭弹窗前的回调
function handleClose() {
  shows.value = false
}
</script>

<style scoped lang="scss"></style>
